<template>
  <div class="newsinfo-container">
    <!-- 标题区域 -->
    <h3 class="title">{{ newsInfo.title }}</h3>
    <p class="title2">
      <span>{{ newsInfo.add_time | date-format }}</span>
      <span>点击:{{ newsInfo.click }}次</span>
    </p>
    <!-- 内容区域 -->
    <div class="content" v-html="newsInfo.content"></div>

    <!-- 评论（子组件）区域  顺便传一个id过去-->
    <comment-box :id="this.id"></comment-box>
  </div>
</template>

<script>
// 1. 导入评论子组件
import comment from "../subcomponents/comment.vue";
export default {
  data() {
    return {
      id: this.$route.params.id,
      newsInfo: {}
    };
  },
  created() {
    this.getNewsInfo();
  },
  methods: {
    getNewsInfo() {
      this.$http.get("api/getnew/" + this.id).then(result => {
        console.log(result.body);
        console.log(result.status);
        console.log(result.body.status);
        if (result.body.status === 0) {
          //返回的结果是成功的
          this.newsInfo = result.body.message[0];
        } else {
          Toast("加载新闻详情数据失败");
        }
      });
    }
  },
  components: {
    // 2.用来注册子组件的节点
    "comment-box": comment
  }
};
</script>

<style lang="scss">
.newsinfo-container {
  padding: 20px;
  .title {
    font-size: 20px;
  }
}
</style>